package dto

import "gorm.io/gorm"

func Paginate(current int, size int) func(db *gorm.DB) *gorm.DB {
	return func(db *gorm.DB) *gorm.DB {
		if current == 0 {
			current = 1
		}

		switch {
		case size > 100:
			size = 100
		case size <= 0:
			size = 10
		}

		offset := (current - 1) * size
		return db.Offset(offset).Limit(size)
	}
}
